import Taro from "@tarojs/taro";
import { HOST_WEAPP } from "./reauestHost";
import qs from "qs";
const token = "840";
export default function request(params) {
  console.log("params", params);
  function createFormData(params = {}, boundary = "") {
    let result = "";
    let formdata = new FormData();
    formdata.append("username", "123");
    formdata.append("password", "123");
    // for (let i in params) {
    //   formdata.append('name')
    // }
    // // 如果obj不为空，则最后一行加上boundary
    // if (result) {
    //   result += `\r\n--${boundary}`;
    // }
    console.log(formdata);
    return formdata;
  }
  return new Promise((resolve, reject) => {
    let { url, method = "GET", data } = params;
    // data = createFormData(data);
    console.log("data", data);
    let contentType = "application/x-www-form-urlencoded";
    contentType = params.contentType || contentType;
    return Taro.request({
      isShowLoading: false,
      url: HOST_WEAPP + url,
      data,
      method: method,
      header: { "content-type": contentType, token: token }, // 默认contentType ,预留token
      // eslint-disable-next-line no-unused-vars
      success(res) {
        resolve(res.data);
      },
      error(e) {
        // eslint-disable-next-line no-undef
        reject(logError("api", "请求接口出现问题", e));
      },
    });
  });
}
